var apis = {
	"pc_taskitem"    :"https://stuapi.kidcastle.cn/Stutask/SubmitTask",//088->任务中心->提交完成学生任务
	"pc_no_taskitem" :"https://stuapi.kidcastle.cn/Hour/AddKCTVGold"  //161->TV->看KCTV增加学生金币
};
// console.log(apis);

var params = {
	"token"      : getUrlParam('token'),
	"member_id"  : getUrlParam('member_id'),
	"student_id" : getUrlParam('student_id'),
	"clientType" : getUrlParam('clientType'),
	"media_id"   : getUrlParam('media_id'),
	"taskitem_id": getUrlParam('taskitem_id')
};
// console.log(params);

//播放结束
function videoEnded(){
	if(params.clientType == 'app'){
		goSkipUni();
	}else{
		reqApi();
	}
}


//播放结束 请求部分API
function reqApi(){
	if(params.taskitem_id){
		$.ajax({
			type:"POST",
			url :apis.pc_taskitem,
			data:{
				"token"      : params.token,
				"member_id"  : params.member_id,
				"student_id" : params.student_id,
				"taskitem_id": params.taskitem_id,
			},
			success: function(res){
				console.log(res);
			},
			error:function(e){
				console.log(e);
			}
		});
		
	}else{
		$.ajax({
			type:"POST",
			url :apis.pc_no_taskitem,
			data:{
				"token"      : params.token,
				"member_id"  : params.member_id,
				"student_id" : params.student_id,
				"media_id"   : params.media_id,
			},
			success: function(res){
				console.log(res);
			},
			error:function(e){
				console.log(e);
			}
		});
	}
	
	
}

//播放结束 跳转
function goSkipUni(){
	window.location.href = "uniwebview://videoFinish";
	//window.location.href = "http://www.baidu.com";
}

//获取URL参数
function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg);  //匹配目标参数
	if (r != null) return unescape(r[2]); return null; //返回参数值
}